/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.haiberg.osgi.bundle.reportservice.utils;

import com.haiberg.osgi.bundle.reportservice.activator.Activator;
import com.haiberg.osgi.bundle.utils.FileUtils;
import java.io.File;
import org.apache.commons.lang.StringUtils;
import org.osgi.framework.Bundle;

/**
 *
 * @author gyue
 */
public class ReportUtils {
    
    public static String getReportAbsolutePath(String fileName,String appName){
        String reportParentName = getReportDirectoryPath(appName);
        if(reportParentName != null){
            return reportParentName + File.separator + fileName;
        }
        return null;
    }
    
    public static String getReportDirectoryPath(String appName){
        if(StringUtils.isBlank(appName)){
            appName = Constants.DEFAULT_APP_USERNAME_STRING;
        }
        Bundle bundle = Activator.getContext().getBundle();
        String bundleResourceBasePath = FileUtils.getBundleBasePath(bundle);
        if(bundleResourceBasePath != null){
            return StringUtils.join(new String[]{
                bundleResourceBasePath , "data" , "reportservice" , appName, "reports"
            }, File.separator);
        }
        return null;
    }
}
